package com.foreknow.dao.impl;

import com.foreknow.bean.Person;
import com.foreknow.dao.PersonDao;
import com.foreknow.db.DBManager;
import com.foreknow.db.JdbcTemplate;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class PersonDaoImpl extends BaseDao implements PersonDao {
    @Override
    public List<Person> queryAll() {
        return null;
    }

    @Override
    public boolean addPerson(Person person) throws SQLException{
        String sql = "insert into person values(gb.nextval,?,?,?,?,?)";
        int isRight = jdbcTemplate.update(sql,person.getName(),person.getPass(),person.getEmail(),person.getTitle(),person.getContent());
        return isRight==1;
    }

    @Override
    public boolean deletePersonById(String id)throws SQLException {
        return false;
    }

    @Override
    public boolean updatePerson(Person person)throws SQLException {
        return false;
    }

    @Override
    public Person isLogin(String name, String pass)throws SQLException {
        EntityMapping mapping = mappingFactory.mapping(MappingFactory.PERSON_MAPPING);//PersonMapping对象
        List<Object> list = jdbcTemplate.query("select * from person where name=? and pass=?",mapping,name,pass);
        if(list.size()>0){
            return (Person) list.get(0);
        }
        return null;
    }


    @Override
    public Person getPersonById(String id)throws SQLException {
        return null;
    }
}
